import {
  Fragment, Text, Comment, createBlock, openBlock
} from 'vue';

import type {
  VNode, VNodeTypes, VNodeChild
} from 'vue';

type Children = VNodeTypes[] | VNodeTypes

const TEMPLATE = 'template';

export enum PatchFlags {
  TEXT = 1 << 0, // 1
  CLASS = 1 << 1, // 2
  STYLE = 1 << 2, // 4
  PROPS = 1 << 3, // 8
  FULL_PROPS = 1 << 4, // 16
  HYDRATE_EVENTS = 1 << 5, // 32
  STABLE_FRAGMENT = 1 << 6, // 64
  KEYED_FRAGMENT = 1 << 7, // 128
  UNKEYED_FRAGMENT = 1 << 8, // 256
  NEED_PATCH = 1 << 9, // 512
  DYNAMIC_SLOTS = 1 << 100, // 1024
  HOISTED = -1,
  BAIL = -2,
}


export const isFragment = (node: VNodeChild) => (node as VNode).type === Fragment;

export const isText = (node: VNodeChild) => (node as VNode).type === Text;

export const isComment = (node: VNodeChild) => (node as VNode).type === Comment;

export const isTemplate = (node: VNodeChild) => (node as VNode).type === TEMPLATE;

// eslint-disable-next-line require-jsdoc
export function renderBlock(
    node: VNodeTypes,
    props: any,
    children?: Children,
    patchFlag?: number,
    patchProps?: string[]
) {
  return (openBlock(), createBlock(
      node, props, children, patchFlag, patchProps
  ));
}
